/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ban.nmpp.config;

import cn.ac.iie.di.ban.nmpp.se.server.NEWMPP2MStartup;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.log4j.Logger;

/**
 *
 * @author wjt
 */
public class ConfigurationTablesReader {

    private static Logger logger = Logger.getLogger(ConfigurationTablesReader.class.getName());

    
    public static ArrayList<HashMap<String, String>> executeQuery() {
        Configuration conf = Configuration.getConfiguration(NEWMPP2MStartup.confPath + File.separator + "ban-ycl-common-mpp.properties");
        ArrayList<HashMap<String, String>> Result = new ArrayList<HashMap<String, String>>();
        String cstData = conf.getString("cstTable", "");
        String[] cstDataSplit = cstData.split("[#]");
        logger.info("threre are" + cstDataSplit.length + "tables");
        for (int i = 0; i < cstDataSplit.length; i++) {
            HashMap<String, String> tables = new HashMap<String, String>();
            String[] cstDataSplits = cstDataSplit[i].split("[@]");
            String ruleName = cstDataSplits[0].trim();
            String sGroup = cstDataSplits[1].trim();
            String ruleContent = cstDataSplits[2].trim();
            tables.put("rulename", ruleName);
            tables.put("sgroup", sGroup);
            tables.put("rulecontent", ruleContent);
            logger.info("rulename "+ruleName +" sgroup "+sGroup+" rulecontent "+ruleContent );
            Result.add(tables);
        }
        logger.info("conf with tables" + Result);
        return Result;

    }
}
